<script setup lang="ts">
import { computed } from "vue";
import { useRouter, useRoute } from "vue-router";
import { ElMessageBox } from "element-plus";

const router = useRouter();
const route = useRoute();

const menuItems = [
  { id: "chat", name: "首页", path: "/internal/chat" },
  { id: "users", name: "用户管理", path: "/internal/users" },
  {
    id: "question",
    name: "问题管理",
    path: "/internal/question",
  },
  {
    id: "history",
    name: "对话历史",
    path: "/internal/history",
  },
  {
    id: "config",
    name: "配置管理",
    path: "/internal/config",
  },
];

const currentMenu = computed(() => {
  return route.path;
});

const navigateTo = (path: string) => {
  router.push(path);
};

const logout = () => {
  ElMessageBox.confirm("确定要退出登录吗?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      localStorage.removeItem("token");
      router.push("/login");
    })
    .catch(() => {
      // 用户取消操作
    });
};
</script>

<template>
  <div class="internal-layout">
    <!-- 顶部导航栏 -->
    <div class="top-navbar">
      <div class="navbar-left">
        <div class="logo">
          <span class="logo-text">内部管理系统</span>
        </div>
      </div>
      <div class="navbar-right">
        <button class="logout-btn" @click="logout">退出登录</button>
      </div>
    </div>

    <div class="main-layout">
      <!-- 左侧菜单 -->
      <div class="side-menu">
        <div
          v-for="item in menuItems"
          :key="item.id"
          class="menu-item"
          :class="{ active: currentMenu === item.path }"
          @click="navigateTo(item.path)"
        >
          <span class="menu-name">{{ item.name }}</span>
        </div>
      </div>

      <!-- 右侧内容区 -->
      <div class="content-area">
        <router-view />
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.internal-layout {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 50%, #0a0e27 100%);
  position: relative;
}

.top-navbar {
  height: 60px;
  background: linear-gradient(
    135deg,
    rgba(49, 190, 255, 0.08) 0%,
    rgba(49, 190, 255, 0.03) 100%
  );
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(49, 190, 255, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  position: relative;
  z-index: 10;
}

.navbar-left {
  display: flex;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 600;
  color: #f6f9fe;
  font-family: "YouSheBiaoTiHei", sans-serif;
  text-shadow: 0 2px 8px rgba(49, 190, 255, 0.3);
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logout-btn {
  padding: 10px 20px;
  background: linear-gradient(
    135deg,
    rgba(49, 190, 255, 0.15) 0%,
    rgba(49, 190, 255, 0.08) 100%
  );
  border: 1px solid rgba(49, 190, 255, 0.3);
  border-radius: 8px;
  color: rgba(49, 190, 255, 0.9);
  font-size: 14px;
  font-family: "Alibaba PuHuiTi", sans-serif;
  cursor: pointer;
  transition: all 0.3s ease;
  outline: none;

  &:hover {
    background: linear-gradient(
      135deg,
      rgba(49, 190, 255, 0.25) 0%,
      rgba(49, 190, 255, 0.15) 100%
    );
    border-color: rgba(49, 190, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(49, 190, 255, 0.3);
    color: #31beff;
  }

  &:active {
    transform: translateY(0);
  }
}

.main-layout {
  flex: 1;
  display: flex;
  position: relative;
  z-index: 1;
}

.side-menu {
  width: 220px;
  background: linear-gradient(
    135deg,
    rgba(49, 190, 255, 0.06) 0%,
    rgba(49, 190, 255, 0.02) 100%
  );
  backdrop-filter: blur(20px);
  border-right: 1px solid rgba(49, 190, 255, 0.15);
  padding: 20px 0;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.2);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  cursor: pointer;
  transition: all 0.3s ease;
  color: rgba(246, 249, 254, 0.7);
  margin: 6px 16px;
  border-radius: 10px;
  position: relative;
  font-family: "Alibaba PuHuiTi", sans-serif;

  .menu-name {
    font-size: 15px;
    font-weight: 500;
  }

  &::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 60%;
    background: linear-gradient(90deg, rgba(49, 190, 255, 0.8), transparent);
    border-radius: 0 4px 4px 0;
    transition: width 0.3s ease;
  }

  &:hover {
    background: rgba(49, 190, 255, 0.08);
    color: rgba(246, 249, 254, 0.95);
    transform: translateX(4px);

    &::before {
      width: 4px;
    }

    .menu-icon {
      transform: scale(1.1);
    }
  }

  &.active {
    background: linear-gradient(
      135deg,
      rgba(49, 190, 255, 0.2) 0%,
      rgba(49, 190, 255, 0.1) 100%
    );
    color: #31beff;
    border: 1px solid rgba(49, 190, 255, 0.3);
    box-shadow: 0 4px 12px rgba(49, 190, 255, 0.2);

    &::before {
      width: 4px;
    }

    .menu-icon {
      color: #31beff;
      text-shadow: 0 0 8px rgba(49, 190, 255, 0.5);
    }
  }
}

.content-area {
  flex: 1;
  overflow: hidden;
  background: rgba(10, 14, 39, 0.3);
  backdrop-filter: blur(10px);
}
</style>
